package server

import (
	"fmt"
	"gin_gorm/web/conf"
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
	"net/http"
	"time"
)

type AppProgram struct {
	conf   *conf.Config
	server *http.Server
	db     *gorm.DB
}

func newAppProgram(
	conf *conf.Config,
	server *http.Server,
	db *gorm.DB,
) *AppProgram {
	return &AppProgram{
		conf:   conf,
		server: server,
		db:     db,
	}
}
func newDB(conf *conf.Config) *gorm.DB {
	return &gorm.DB{}
}
func newServer(conf *conf.Config, engine *gin.Engine) *http.Server {
	return &http.Server{
		Addr:        fmt.Sprintf("%s:%s", conf.App.Addr, conf.App.Port),
		Handler:     engine,
		ReadTimeout: time.Second * 3,
	}
}

func (app *AppProgram) StartApp() {
	app.server.ListenAndServe()
}
